package com.liuyk.commonlib.dialog;

import android.content.Context;
import android.text.TextUtils;

/**
 * 弹窗快捷使用
 * <p>
 * Created by liuyakui on 2020/6/23
 */
public class DialogUtils {

    public static Builder builder(Context context) {
        return new Builder(context);
    }

    public static class Builder {
        private CommonDialog mCommonDialog;

        public Builder(Context context) {
            mCommonDialog = new CommonDialog(context);
        }

        //弹窗标题
        public Builder setTitle(String title) {
            if (!TextUtils.isEmpty(title)) {
                mCommonDialog.getTitleText().setText(title);
            }
            return this;
        }

        //设置标题可见
        public Builder setTitleVisibility(int visibility) {
            mCommonDialog.getTitleText().setVisibility(visibility);
            return this;
        }

        //左边按钮文案
        public Builder setLeftBtnText(String leftText) {
            if (!TextUtils.isEmpty(leftText)) {
                mCommonDialog.getLeftText().setText(leftText);
            }
            return this;
        }

        //左边按钮字体颜色
        public Builder setLeftBtnTextColor(int leftTextColor) {
            if (leftTextColor != -1) {
                mCommonDialog.getLeftText().setTextColor(leftTextColor);
            }
            return this;
        }

        //左边按钮是否可见
        public Builder setLeftBtnVisibility(int visibility) {
            mCommonDialog.getLeftText().setVisibility(visibility);
            return this;
        }

        //右边按钮文案
        public Builder setRightBtnText(String rightText) {
            if (!TextUtils.isEmpty(rightText)) {
                mCommonDialog.getRightText().setText(rightText);
            }
            return this;
        }

        //右边按钮字体颜色
        public Builder setRightBtnTextColor(int rightTextColor) {
            if (rightTextColor != -1) {
                mCommonDialog.getRightText().setTextColor(rightTextColor);
            }
            return this;
        }

        //右边按钮是否可见
        public Builder setRightBtnVisibility(int visibility) {
            mCommonDialog.getRightText().setVisibility(visibility);
            return this;
        }

        //内容文案
        public Builder setContentText(String contentText) {
            if (!TextUtils.isEmpty(contentText)) {
                mCommonDialog.getContentText().setText(contentText);
            }
            return this;
        }

        //内容字体颜色
        public Builder setContentTextColor(int contentTextColor) {
            if (contentTextColor != -1) {
                mCommonDialog.getContentText().setTextColor(contentTextColor);
            }
            return this;
        }

        //内容是否可见
        public Builder setContentVisibility(int visibility) {
            mCommonDialog.getContentText().setVisibility(visibility);
            return this;
        }

        //左边按钮点击事件
        public Builder setNeutralClickListener(BaseDialog.NeutralClickListener neutralClickListener) {
            if (neutralClickListener != null) {
                mCommonDialog.setNeutralClickListener(neutralClickListener);
            }
            return this;
        }

        //右边按钮点击事件
        public Builder setPositiveClickListener(BaseDialog.PositiveClickListener positiveClickListener) {
            if (positiveClickListener != null) {
                mCommonDialog.setPositiveClickListener(positiveClickListener);
            }
            return this;
        }

        public void show() {
            if (!mCommonDialog.isShowing()) {
                mCommonDialog.show();
            }
        }
    }
}
